var pinDigitron = 2; //管脚D2连接到数码管的A脚，D3连B... D9连h

function setup() {
  for(var x=0; x<14; x++)
    pinMode(pinDigitron+x, OUTPUT); //设置各脚为输出状态
}

//在数码管中显示数字的函数
function displayDigit(digit) {
    //定义一个数组表：不同数字的abcdefgh各段的取值
    var abcdefgh = new Array();
    abcdefgh[0] = [1,1,1,1,1,1,0,0];  //0
    abcdefgh[1] = [0,0,0,0,1,1,0,0];  //1
    abcdefgh[2] = [1,1,0,1,1,0,1,0];  //2
    abcdefgh[3] = [1,1,1,1,0,0,1,0];  //3
    abcdefgh[4] = [0,1,1,0,0,1,1,0];  //4
    abcdefgh[5] = [1,0,1,1,0,1,1,0];  //5
    abcdefgh[6] = [1,0,1,1,1,1,1,0];  //6
    abcdefgh[7] = [1,1,1,0,0,0,0,0];  //7
    abcdefgh[8] = [1,1,1,1,1,1,1,0];  //8
    abcdefgh[9] = [1,1,1,1,0,1,1,0];  //9
    abcdefgh[10] = [1,1,1,0,1,1,1,0];  //A
    abcdefgh[11] = [0,0,1,1,1,1,1,0];  //b
    abcdefgh[12] = [1,0,0,1,1,1,0,0];  //C
    abcdefgh[13] = [0,1,1,1,1,0,1,0];  //d
    abcdefgh[14] = [1,0,0,1,1,1,1,0];  //E
    abcdefgh[15] = [1,0,0,0,1,1,1,0];  //F


    digitalWrite(12, 1);

    if ( digit >= 16 )
        return;
    for (var x = 0; x < 8; x++)
        digitalWrite( pinDigitron + x, abcdefgh[digit][x] );
}

function loop() {
   //在数码管中显示0-9,A-F各个数字
   for (var x = 0; x < 16; x++) {
     displayDigit(x);  //调用displayDigit()子函数，显示数字
     delay(1000); //等待1000毫秒
   }
  // displayDigit(1);
}
